﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "Common/ConfigFileManager.h"


FString ConfigFileManager::GetFileNameFromPath(const FString& FilePath)
{
	if (FilePath.IsEmpty()) return FString("");
	FString LValue, RValue;
	FilePath.Split("/", &LValue, &RValue);
	if (LValue.IsEmpty() && RValue.IsEmpty()) return FilePath;
	else return GetFileNameFromPath(RValue);
}

FString ConfigFileManager::LoadConfigFileToString(const FString& FilePath)
{
	FString temp;
	FFileHelper::LoadFileToString(temp, *FilePath);
	return temp;
}

bool ConfigFileManager::SaveConfigFile(const FString& Content, FString& FilePath)
{
	{
		// FString tyty=GInputIni;
		// bool op=FConfigCacheIni::LoadGlobalIniFile(FilePath,TEXT("TestConfig"));
		// UEngine::Re();
		// if(op)
		// {
		// 	// UE_LOG(LogTemp, Warning, TEXT("LoadGlobalIniFile Success"));
		// }
		int32 t = 0;
		FConfigCacheIni* TTT = GConfig;
		FConfigFile* kllk = TTT->FindConfigFile(FilePath);
		const bool te = GConfig->GetInt(TEXT("/Script/GKConfig.ConfigRTTest"),TEXT("ConfigValue"), t, "TestConfig");
		if (te)
		{
			// UE_LOG(LogTemp, Warning, TEXT("Now ConfigValue = %d"), t);
		}
		else
		{
			// UE_LOG(LogTemp, Warning, TEXT("Error Read Config"));
		}
	}
	const bool result = FFileHelper::SaveStringToFile(Content, *FilePath);
	if (result)
	{
		GConfig->Flush(false, *FilePath);
	}
	{
		int32 t = 0;
		const bool te = GConfig->GetInt(TEXT("/Script/GKConfig.ConfigRTTest"),TEXT("ConfigValue"), t, "TestConfig");
		if (te)
		{
			// UE_LOG(LogTemp, Warning, TEXT("Now ConfigValue = %d"), t);}
		}
		else
		{
			// UE_LOG(LogTemp, Warning, TEXT("Error Read Config"));}
		}
		return result;
	}
}
